<?php
// Registered members list page
//
// digiboard by digitalboom.org
// http://www.digitalboom.org
//
// Information Technology program
// Sirindhorn International Institute of Technology
// Thammasat University, Rangsit Campus
// http://www.siit.tu.ac.th
//
// authors: hoho, BiGGA, bact'
// first created on: 2003 May 04
// last modified on: 2003 May 21
// last modified by: hoho

include("settings/config.inc.php");
include("settings/accounts.inc.php");
include("lib/util.inc.php");
include("lib/sh.inc.php");
include("lib/users_function.inc.php");

global $DGB;

extract($_POST);
extract($_GET);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Member List - <?=$DGB["WEBBOARD_NAME"];?></title>
<meta http-equiv="Content-Type" content="text/html; charset=<?=$DGB["ENCODING"];?>">
<link rel="stylesheet" href="<?=$DGB["STYLESHEET"];?>" type="text/css">
<script language="JavaScript">
<!--
var remote=null;
function nw(n,u,w,h,x) {
 args="width="+w+",height="+h+",resizable=yes,scrollbars=yes,status=0";
 n = n+"<?=$Topic_ID;?>";
 remote=window.open(u,n,args);
 if (remote != null) {
  if (remote.opener == null)
   remote.opener = self;
 }
 if (x == 1) { return remote; }
}

function put(m) {
 s = document.compose.msgdetail.value;
 document.compose.msgdetail.value = s + m;
} 
//-->
</script>

<!-- this object is for MSN features, works only in Internet Explorer -->
<object id=objMessengerApp height=0 codetype=application/x-oleobject width=0
classid=clsid:FB7199AB-79BF-11d2-8D94-0000F875C541> 
</object>

</head>

<?php
//does user already logged in?
$AlreadyLogin = 0;
if($DGB["ENABLE_LOGIN"] == true) {
 if (isset($Password) && isset($Username)) {
  shad2pw($Password);
  $AlreadyLogin = CheckUser($Username, $Password);
 }
}

// select all users from DB
$db_link = dgb_db_connect();
$query = "SELECT * FROM ".$DGB["DB_USERS_TABLE"]."";
$result = mysql_query($query,$db_link);
$num_rows = mysql_num_rows($result);
$totalpage = round($num_rows/20)+1; //show 20 users per page

//check which page
if(!isset($page)) {
 $page = 1; //default = first page
}

//check sort by
if(!isset($sort)) {
 $sort = "UserName"; //default = sort by UserID
}

//prepare 'order by' for SQL statement
switch($sort) {
 case "UserID": $orderby="UserID"; break;
 case "Topics": $orderby="TotalTopicPost DESC"; break;
 case "Answers": $orderby="TotalAnswerPost DESC"; break;
 case "Posts": $orderby="((TotalTopicPost *3)+TotalAnswerPost) DESC"; break;//fix to points
 case "UserName": $orderby="UserName"; break;
 case "Level": $orderby="((TotalTopicPost *3)+TotalAnswerPost) DESC"; break;
 case "UserID": $orderby="UserID"; break;
}

//go!
$goto=($page-1)*20;
$query = "SELECT * FROM ".$DGB["DB_USERS_TABLE"]." ORDER BY $orderby LIMIT $goto,20";
$result = mysql_query($query,$db_link);
$num_rows = mysql_num_rows($result);
?>

<body bgcolor="#FFFFEE">
<table width="100%" border=0 cellspacing=1 cellpadding=1 align="center">
 <tr> 
  <td class="pHead" align="center"> 
   <?=$DGB["WEBBOARD_NAME"];?> / Member List
  </td>
 </tr>
 <tr> 
  <td class="pSubHead" align="center"> <font color="#FFFFFF"><b>Total Registered Members: 
   <? $TotalMembers = AllBoardsStats($DGB["DB_USERS_TABLE"]);
    echo $TotalMembers1 = number_format($TotalMembers, 0, '.', ',');?></b></font></td>
 </tr>
  <tr> 
  <td align="center"><font size=2>Sort By  <a title="sort by ID" href="members.php?sort=UserID"><?if($sort=="UserID"){?><b>UserID</b><?}else{?>UserID<?}?></a> | <a title="sort by Name" href="members.php?sort=UserName"><?if($sort=="UserName"){?><b>Name</b><?}else{?>Name<?}?></a> | <a title="sort by Level" href="members.php?sort=Level"><?if($sort=="Level"){?><b>Level</b><?}else{?>Level<?}?></a> | <a title="sort by numbers of Topics posted" href="members.php?sort=Topics"><?if($sort=="Topics"){?><b>Topics</b><?}else{?>Topics<?}?></a> | <a title="sort by numbers of Answers posted" href="members.php?sort=Answers"><?if($sort=="Answers"){?><b>Answers</b><?}else{?>Answers<?}?></a> | <a title="sort by 'Post Points'" href="members.php?sort=Posts"><?if($sort=="Posts"){?><b>Points</b><?}else{?>Points<?}?></a></font></td>
 </tr>
 <tr>
  <td><font size=2>Page 
  <? for($i=1;$i<$totalpage;$i++) {
     if($i==($page)) {
       echo "<b>[$i]</b> "; //display current page in bold, no link
     } else {
       echo "<a href=\"members.php?page=$i&sort=$sort\">$i</a> ";
     }
		}?></font></td>
 </tr>
 <tr>
  <td>
   <table width=98% border=0 cellspacing=0 cellpadding=1 align="center" bgcolor="#996699">
    <tr>
     <td valign="top">
      <table width=100% border=0 cellspacing=1 cellpadding=1 align="center">
      <tr>
      <td colspan=8 class="pHead"> </td>
      </tr>
      <tr align="center" class="pSubHead"> 
      <td><a title="sort by Name" href="members.php?sort=UserName"><font color="#ffffff"><?if($sort=="UserName"){?><b>Name</b><?}else{?>Name<?}?></font></a></td>
      <td><a title="sort by Level" href="members.php?sort=Level"><font color="#ffffff"><?if($sort=="Level"){?><b>Level</b><?}else{?>Level<?}?></font></a></td>
      <td><font color="#ffffff">Email</font></td>
      <td><font color="#ffffff">MSN</font></td>
      <td><font color="#ffffff">ICQ</font></td>
      <td><a title="sort by numbers of Topics posted" href="members.php?sort=Topics"><font color="#ffffff"><?if($sort=="Topics"){?><b>Topics</b><?}else{?>Topics<?}?></font></a></td>
      <td><a title="sort by numbers of Answers posted" href="members.php?sort=Answers"><font color="#ffffff"><?if($sort=="Answers"){?><b>Answers</b><?}else{?>Answers<?}?></font></a></td>
      <td><a title="sort by 'Post Points'" href="members.php?sort=Posts"><font color="#ffffff"><?if($sort=="Posts"){?><b>Points</b><?}else{?>Points<?}?></font></a></td>
      </tr>
      <? for($i=0;$i<$num_rows;$i++) {
          $data = mysql_fetch_row($result); ?>
      <tr valign="top" bgcolor="#FFFFFF" class="UserOnline">
      <td width="20%"><a class="tpPosterInfo"
      href="javascript:nw('profile','profile.php?ProfileName=<?=$data[1];?>',350,500,0)"><?=$data[1];?></a></td>
      <td width="12%"> 
      <?//Topic 3 points, Answer 1 points
      $Totalpoints = ($data[17]*3)+$data[18];?>
      <?=CheckRanking($Totalpoints);?>
      </td>
      <td width="12%" align="center">
      <? //show link for e-mail
      if(($AlreadyLogin == "1") && ($data[3] != "")) {?>
      <a href="mailto:<?=$data[3];?>">Send a Mail</a>
			<?}?>
			</td>
      <td width="5%" align="center"> 
			<? //show link for add MSN id to contact list
      if(($AlreadyLogin == "1") && ($data[5] != "")) {?>
      <a title="add to my contact list" href='javascript:objMessengerApp.LaunchAddContactUI("<?=$data[5];?>")'>Add</a>
      <?}?>
			</td>
      <td width="11%" align="center"><?=$data[4];?></td>
			<td width="4%" align="center"><?=$data[17]?></td>
      <td width="5%" align="center"><?=$data[18];?></td>
      <td width="4%" align="center"><?=$Totalpoints;?></td>
      </tr>
      <?}?>
      </table>
      </td>
     </tr>
    </table>
    </td>
 </tr>
</table>
<br>
<center><a href="list.php">back to webboard</a></center>
<br>
</body>
</html>
